package bid.yanhj.yanhaijiang.intent;

import android.content.Intent;
import android.print.PrinterId;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SecondActivity extends AppCompatActivity {

    private EditText userNameEv, pwdEv;
    private Button jump2MainBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        userNameEv = findViewById(R.id.user_name_et_second);
        pwdEv = findViewById(R.id.pwd_et_second);
        jump2MainBtn = findViewById(R.id.jump_to_main_btn);

        final Intent intent = getIntent();
        String userName = intent.getStringExtra("userName");

        userNameEv.setText(userName);

        // 拿注册页信息返回到第一个页面
        jump2MainBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String user = userNameEv.getText().toString();
                String pwd = pwdEv.getText().toString();

                // 传值
                Intent result = new Intent();
                result.putExtra("userName", user);
                result.putExtra("pwd", pwd);

                // 传Activity的状态 值
                setResult(1,result);
                // 结束当前的Activity
                finish();
            }
        });
    }
}
